#include "myaction.h"
#include<QSplitter>
#include<QLabel>
MyAction::MyAction(QObject* parent)
    :QWidgetAction(parent)
{
    //创建行编辑器
    lineEdit = new QLineEdit();
    //连接信号跟槽，触发回车信号和发送文本的槽函数关联
    connect(lineEdit,&QLineEdit::returnPressed,this,&MyAction::sendText);

}



void MyAction::sendText()
{
    emit getText(lineEdit->text());
    lineEdit->clear();
}


QWidget* MyAction::createWidget(QWidget* parent)
{
    //parent不继承QMenu 并且不继承QToolBar
    if(!(parent->inherits("QMenu"))&&!(parent->inherits("QToolBar")))
    {
        qDebug()<<"这里！！！";
        return 0;
    }
    qDebug()<<"nihao!";
    QSplitter* spliter = new QSplitter(parent);
    QLabel* label = new QLabel;
    label->setText(tr("插入文本"));
    spliter->addWidget(label);
    spliter->addWidget(lineEdit);
    return spliter;
}


